//
//  DownTableViewCell.m
//  HimalayaMusic
//
//  Created by dllo on 16/1/8.
//  Copyright © 2016年 WXCLegendary. All rights reserved.
//

#import "DownTableViewCell.h"

@implementation DownTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        [self createViews];
        
        
        
        
    }
    return self;
}

- (void)createViews {
    self.mainImage = [[UIImageView alloc] init];
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    
    self.leftLabel = [[UILabel alloc] init];
    self.leftLabel.font = [UIFont systemFontOfSize:14];
    self.rightLabel = [[UILabel alloc] init];
    self.rightLabel.font = [UIFont systemFontOfSize:14];
    self.playIcon = [[UIImageView alloc] init];
    self.playIcon.image = [UIImage imageNamed:@"play"];
    self.albumIcon = [[UIImageView alloc] init];
    self.albumIcon.image = [UIImage imageNamed:@"album"];
    self.authorLabel = [[UILabel alloc] init];
    self.authorLabel.font = [UIFont systemFontOfSize:13];
    self.authorLabel.textColor = [UIColor grayColor];
    [self addSubview:self.mainImage];
    [self addSubview:self.titleLabel];
    [self addSubview:self.leftLabel];
    [self addSubview:self.rightLabel];
    [self addSubview:self.playIcon];
    [self addSubview:self.albumIcon];
    [self addSubview:self.authorLabel];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.mainImage.frame = CGRectMake(10, 10, self.height - 20, self.height - 20);
    
    
//    //label的自适应高度
//    
//    NSDictionary *TagLabeldic = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
//    CGRect tagRect = [self.downModel.title boundingRectWithSize:CGSizeMake(self.width - self.mainImage.right - 20, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:TagLabeldic context:nil];

    self.titleLabel.frame = CGRectMake(self.mainImage.right + 10, 10, self.width - self.mainImage.right - 20, 40);

    
    self.authorLabel.frame = CGRectMake(self.titleLabel.left, self.titleLabel.bottom, self.width - self.mainImage.right, 10);
    self.playIcon.frame = CGRectMake(self.titleLabel.left, self.mainImage.bottom - 15, 10, 10);
    
    self.leftLabel.frame = CGRectMake(self.playIcon.right + 5, self.playIcon.top, 100, self.playIcon.height);
    self.albumIcon.frame = CGRectMake(self.leftLabel.right + 20, self.playIcon.top, 10, 10);
    self.rightLabel.frame = CGRectMake(self.albumIcon.right + 5, self.albumIcon.top, 100, self.playIcon.height);
}


- (void)setDownModel:(DownModel *)downModel {
    if (_downModel != downModel) {
        _downModel = downModel;
    }
    [self.mainImage sd_setImageWithURL:[NSURL URLWithString:self.downModel.coverMiddle]];
    self.titleLabel.text = self.downModel.title;
    self.authorLabel.text = self.downModel.nickname;
    CGFloat count = self.downModel.playsCounts.floatValue / 10000;
    
    
    self.leftLabel.text = [NSString stringWithFormat:@"%.1f万次", count];
    
    NSString *track = [NSString stringWithFormat:@"%ld集", self.downModel.tracksCounts.integerValue];
    
    
    
    self.rightLabel.text = track;
    
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
